﻿using Newtonsoft.Json;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ActionSystem.Core
{
    [System.Serializable]
    public class BaseStateActionConfig
    {
        #region 配置数据
        /// <summary>
        /// 能否被下一个状态action继承使用
        /// </summary>
        [XMLib.CustomLabel("能否被继承")]
        public bool canInherited = false;
        /// <summary>
        /// 能否继承使用上一个状态的action
        /// </summary>
        [XMLib.CustomLabel("能否继承")]
        public bool canInheriting = false;
        /// <summary>
        /// action起始
        /// </summary>
        [SerializeField]
        [XMLib.CustomLabel("开始帧")]
        public int begin = 0;
        /// <summary>
        /// action长度
        /// </summary>
        [SerializeField]
        [XMLib.CustomLabel("持续帧数")]
        public int length = 1;

        /// <summary>
        /// action是否具有循环属性
        /// </summary>
        [XMLib.CustomLabel("是否循环")]
        public bool loop = false;
        #endregion

        [JsonIgnore]
        public int Length
        {
            get => length;
            set
            {
                if(value<1)
                {
                    value = 1;
                }
                length = value;
            }
        }
        [JsonIgnore]
        public bool Loop => loop;
        /// <summary>
        /// action起始帧
        /// </summary>
        [JsonIgnore]
        public int Begin
        {
            get
            {
                //可循环则起始必须为0
                if (loop)
                {
                    return 0;
                }else
                {
                    return begin;
                }
            }
            set
            {
                if(value<0)
                {
                    value = 0;
                }
                begin = value;
            }

        }
        /// <summary>
        /// action结束帧
        /// </summary>
        [JsonIgnore]
        public int End
        {
            get
            {
                //可循环则无限长
                if (loop)
                {
                    return int.MaxValue;
                }
                else
                {
                    return begin + length ;
                }
            }
        }
        public override string ToString()
        {
            return $"{GetType().Name}";
        }
    }
}

